package com.example.process.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.common.util.Result;
import com.example.process.ProcessType;
import com.example.process.service.impl.ProcessTypeServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

//用于抑制编译器产生警告信息。 用于抑制编译器产生警告信息。
@SuppressWarnings(value={"unchecked", "rawtypes"})
@Api(tags = "审批类型")
@RestController
@RequestMapping("admin/process/processType")
public class ProcessTypeController {

    @Autowired
    private ProcessTypeServiceImpl processTypeService;

//    @PreAuthorize("hasAuthority('bnt.processType.list')")
    @ApiOperation(value = "获取分页列表")
    @GetMapping("{page}/{limit}")
    public Result index(@PathVariable Long page,
                        @PathVariable Long limit){
        Page<ProcessType> page1 = new Page(page,limit);
        Page<ProcessType> page2 = processTypeService.page(page1);
        return Result.ok(page2);
    }

    @ApiOperation(value = "获取全部审批分类")
    @GetMapping("findAll")
    public Result findAll(){
        return Result.ok(processTypeService.list());
    }

//    @PreAuthorize("hasAuthority('bnt.processType.list')")
    @ApiOperation(value = "获取")
    @GetMapping("get/{id}")
    public Result get(@PathVariable Long id){
        ProcessType processType = processTypeService.getById(id);
        return Result.ok(processType);
    }

//    @PreAuthorize("hasAuthority('bnt.processType.add')")
    @ApiOperation(value = "新增")
    @PostMapping("save")
    public Result save(@RequestBody ProcessType processType){
        boolean save = processTypeService.save(processType);
        return Result.ok(save);
    }

//    @PreAuthorize("hasAuthority('bnt.processType.update')")
    @ApiOperation(value = "修改")
    @PutMapping("update")
    public Result update(@RequestBody ProcessType processType){
//        LambdaQueryWrapper<ProcessType> wrapper = new LambdaQueryWrapper<>();
//        wrapper.eq(ProcessType::getId,processType.getId());
//        processTypeService.update(processType,wrapper);
        boolean b = processTypeService.updateById(processType);
        return Result.ok(b);
    }

//    @PreAuthorize("hasAuthority('bnt.processType.remove')")
    @ApiOperation(value = "删除")
    @DeleteMapping("remove/{id}")
    public Result remove(@PathVariable Long id){
        if ( id == null){
            return Result.fail("id不能为空");
        }
        boolean b = processTypeService.removeById(id);
        return Result.ok(b);
    }

}
